﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RealEstateCenter
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == true)
            {
                if (username_input.Text == "ad" && password_input.Text == "ad")
                {
                    Session["user_type"] = "estate_center";
                }
                else
                {
                    est_login myL = new est_login();
                    if (myL.login(username_input.Text, password_input.Text))
                    {
                        Session["user_type"] = "agency";
                    }
                    else
                    {
                        Session["user_type"] = null;
                    }
                }
            }

            if (Session["user_type"] != null)
            {
                if (Session["user_type"].ToString() == "estate_center")
                {
                    sonuc.Text = "real estate";
                    Response.Redirect("RealEstatePage.aspx");
                }
                else
                {
                    Response.Redirect("AgencyPage.aspx");
                    sonuc.Text = "agency";
                }
            }
            else
            {
                if(!IsPostBack) {sonuc.Text = "Please login using the form on the right side."; } else { sonuc.Text = "<span style=\"font-weight:bold; color: red;\">Invalid login attempt!</span>"; }
            }
        }
    }
}
